package controllers

import (
	"ginstart/models/mysql"
	"ginstart/pkg"
	"github.com/gin-gonic/gin"
	"net/http"
)

type JsonRes struct {
	Code    int
	Message string
	Data    interface{}
}

func UserRegister(c *gin.Context) {
	tel := c.PostForm("tel")
	password := c.PostForm("password")
	user := mysql.Users{
		Tel:      tel,
		Password: pkg.Md5(password),
	}
	err := user.Register()
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"response": JsonRes{
				Code:    500,
				Message: "失败",
				Data:    nil,
			},
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"response": JsonRes{
			Code:    200,
			Message: "成功",
			Data:    user.ID,
		},
	})
}
